import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpclient

import urllib
import json
import datetime
import time

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

def fib(n):
    if n ==0 or n ==1:
        return n
    return fib(n-1) + fib(n -2)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
         data = [
                    ['20140911', 11, 2, 53, 4, 58, 67],
                    ['20140912', 1, 42, 39, 48, 5],
                    ['20140913', 15, 2, 35, 4, 45, 56],
                    ['20140914', 51, 26, 43],
                    ['20140911', 11, 2, 53, 4, 58, 67],
                    ['20140912', 1, 42, 39, 48, 5],
                    ['20140913', 15, 2, 35, 4, 45, 56],
                    ['20140914', 51, 26, 43],
                    ['20140911', 11, 2, 53, 4, 58, 67],
                    ['20140912', 1, 42, 39, 48, 5],
                    ['20140913', 15, 2, 35, 4, 45, 56],
                    ['20140914', 51, 26, 43],
                    ['20140911', 11, 2, 53, 4, 58, 67],
                    ['20140912', 1, 42, 39, 48, 5],
                    ['20140913', 15, 2, 35, 4, 45, 56],
                    ['20140914', 51, 26, 43],
                    ['20140915', 1, 2, 93, 44, 5, 36]]

             heads = [{ name: 'Date', isNumber: false },
                         { name: 'first', isNumber: true },
                         { name: 'second', isNumber: false },
                         { name: 'third', isNumber: true },
                         { name: 'forth', isNumber: false },
                         { name: 'fifth', isNumber: true },
                         { name: 'six', isNumber: true } ];

             periods = [1, 1, 1, 0, 1],
                channels = ['310', '320', '330', '360'],
                versions = ['4.1.2', '4.1.5', '4.1.3', '3.2.4', '3.2'],
                title = 'Test',
                type = 'line',
                start = '2014-09-05',
                end = '2014-09-14';

             datas = {
                data: data,
                heads: heads,
                periods: periods,
                channels: channels,
                versions: versions,
                title: title,
                type: type,
                start: start,
                end: end
            };
        self.write(datas)

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
